import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { IDragDrop } from "../../../../com/mui/manager/IDragDrop";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { ObjCreate } from "../common/ObjCreate";
import { BaseItem } from "../common/BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { ColorConfig } from "../../resource/ColorConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { ResConfig } from "../../resource/ResConfig";
import { DragManager } from "../../../../com/mui/manager/DragManager";
import { DataEvent } from "../../events/DataEvent";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
//class TradePetRenderer
    
    export  class TradePetRenderer extends CellRenderer implements IDragDrop
    {
        constructor()
        {
            super();
            var loc2=null;
            var loc3=null;
            var loc1=new Object /* flash.display.Sprite */();
            loc1.graphics.beginFill(16711680, 0);
            loc1.graphics.drawRect(0, 0, 140, 22);
            loc1.cacheAsBitmap = true;
            addChild(loc1);
            this.mouseChildren = true;
            loc2 = new Object /* flash.display.Sprite */();
            loc3 = GlobalClass.getBitmap("equipment_over");
            loc2.graphics.beginFill(16711680, 0);
            loc2.graphics.drawRect(0, 0, 140, 22);
            loc2.cacheAsBitmap = true;
            loc3.y = 1;
            loc2.addChild(loc3);
            var loc4;
            (loc4 = new Object /* flash.display.Sprite */()).graphics.beginFill(16711680, 0);
            loc4.graphics.drawRect(0, 0, 140, 22);
            loc4.cacheAsBitmap = true;
            this.setStyle("upSkin", loc4);
            this.setStyle("downSkin", loc2);
            this.setStyle("overSkin", loc2);
            this.setStyle("selectedDownSkin", loc2);
            this.setStyle("selectedOverSkin", loc2);
            this.setStyle("selectedUpSkin", loc2);
            this.itemNameLabel = new GLabel();
            addChild(this.itemNameLabel);
            this.itemNameLabel.x = 22;
            this.tranBg = ObjCreate.createColorBox(140, 22, 16777215, 0);
            this.addChild(this.tranBg);
            this.tranBg.doubleClickEnabled = true;
            this.tranBg.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onDoubleClick);
            this.pic = new BaseItem();
            this.pic.isDragAble = false;
            this.pic.isThrowAble = false;
            this.pic.isDropAble = true;
            this.pic.setSize(20, 20);
            this.pic.y = 1;
            this.pic.x = 1;
            addChild(this.pic);
            this.pic.doubleClickEnabled = true;
            this.pic.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onDoubleClick);
            this.usedEffect = new Object /* flash.display.Sprite */();
            this.usedEffect.graphics.beginFill(16711680, 0.7);
            this.usedEffect.graphics.drawRect(0, 0, 140, 22);
            addChild(this.usedEffect);
            this.usedEffect.visible = false;
            this.usedEffect.cacheAsBitmap = true;
            return;
        }

        public get used(): Boolean
        {
            return this._used;
        }

        public set used(arg1: Boolean)
        {
            this._used = arg1;
            this.usedEffect.visible = this._used;
            return;
        }

        public get itemData()
        {
            if (this._itemData) 
            {
                return this._itemData;
            }
            return this._petInfo;
        }

        public set itemData(arg1)
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (typeof arg1 === "itemdata") 
            {
                this._petInfo = null;
                this._itemData = arg1;
                this.pic.itemData = this._itemData;
                if (this._itemData) 
                {
                    this.pic.source = this._itemData.itemInfo.url;
                    this.pic.amount = this._itemData["amount"];
                    loc1 = ColorConfig.instance.getItemColor(this._itemData.itemInfo.item.color);
                    this.itemNameLabel.htmlText = HTMLUtil.addColor(this._itemData.itemInfo.item.name, loc1.color);
                }
                else 
                {
                    this.itemNameLabel.htmlText = "";
                }
            }
            else if (typeof arg1 === "spetinfo") 
            {
                this._itemData = null;
                this._petInfo = arg1;
                if (this._petInfo) 
                {
                    loc2 = "100101";
                    if (loc3 = ResConfig.instance.getInfoByName(loc2 + ".jpg")) 
                    {
                        this.pic.source = loc3.path;
                    }
                    this.itemNameLabel.htmlText = HTMLUtil.addColor(this._petInfo.name, "#FFFFF");
                }
                else 
                {
                    this.pic.source = null;
                    this.itemNameLabel.htmlText = "";
                }
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=0;
            super.data = arg1;
            if (arg1) 
            {
                this.itemData = arg1["itemData"];
                this.used = arg1["used"];
                if (arg1["dragAble"]) 
                {
                    this.pic.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onItemDrag);
                    this.tranBg.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onItemDrag);
                }
            }
            else 
            {
                this.used = false;
                this.pic.source = null;
                this.pic.amount = 0;
                this.pic.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onItemDrag);
                this.tranBg.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onItemDrag);
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        public get dragSource(): Object
        {
            return null;
        }

        public set dragSource(arg1: Object)
        {
            return;
        }

        public get isDragAble(): Boolean
        {
            return true;
        }

        public get isDropAble(): Boolean
        {
            return false;
        }

        public get isThrowAble(): Boolean
        {
            return false;
        }

        public canDrop(arg1: IDragDrop, arg2: IDragDrop): Boolean
        {
            return false;
        }

        /* internal  */onItemDrag(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this.used) 
            {
                DragManager.instance.startDragItem(this);
            }
            return;
        }

        /* internal  */onDoubleClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(GModuleEvent.Event_PetMountListDoubleClick, this.data, false, true));
            return;
        }

        /* internal */ /* var */_source: string;

        /* internal */ /* var */pic: BaseItem;

        /* internal */ /* var */tranBg: Object /* flash.display.Sprite */;

        /* internal */ /* var */itemNameLabel: GLabel;

        /* internal */ /* var */itemAttrLabel: GLabel;

        /* internal */ /* var */buyButton: GLabel;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_buyItemInfo: ShopItemInfo;

        /* internal */ /* var */numStepper: GNumericStepper;

        /* internal */ /* var */buyNumBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */usedEffect: Object /* flash.display.Sprite */;

        /* internal */ /* var */_used: Boolean=false;
    }
